import com.csbc.arithmetic.coupon.BasePromotion;
import com.csbc.arithmetic.coupon.CouponPromotion;
import com.csbc.arithmetic.fruit.Apple;
import com.csbc.arithmetic.fruit.Fruit;
import com.csbc.arithmetic.fruit.Mango;
import com.csbc.arithmetic.fruit.Strawberry;
import com.csbc.arithmetic.market.SuperMarket;
import com.csbc.arithmetic.shopping.Shopping;

import java.util.HashMap;

public class Main {

    final static Apple APPLE;

    final static Strawberry STRAWBERRY;

    final static Mango MANGO;

    static {
        APPLE = new Apple(8);
        STRAWBERRY = new Strawberry(13, true, 0.8);
        MANGO = new Mango(20);
//        HashMap<String, Fruit> hashMap = new HashMap<>();
//        hashMap.put("apple",apple);
//        hashMap.put("strawberry",strawberry);
//        hashMap.put("mango",mango);
//        Shopping.init(hashMap);
    }

    public static void main(String[] args) {
        customerA();
        customerB();
        customerC();
        customerD();
    }

    public static void customerA() {
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName() + " 开始购买");
        Shopping shopping = new Shopping();
        shopping.buy(APPLE, 1);
        shopping.buy(APPLE, 1);
        shopping.buy(STRAWBERRY, 1);
        SuperMarket superMarket = new SuperMarket(shopping);
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName() + " 需要付款:" + superMarket.checkout() + "元");
    }

    public static void customerB() {
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName() + " 开始购买");
        Shopping shopping = new Shopping();
        shopping.buy(APPLE, 5);
        shopping.buy(STRAWBERRY, 8);
        shopping.buy(MANGO, 5);
        SuperMarket superMarket = new SuperMarket(shopping);
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName() + "需要付款:" + superMarket.checkout() + "元");
    }

    public static void customerC() {
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName() + " 开始购买");
        Shopping shopping = new Shopping();
        shopping.buy(APPLE, 1);
        shopping.buy(STRAWBERRY, 1);
        shopping.buy(MANGO, 1);
        Shopping shopping1 = new Shopping();
        shopping1.buy(APPLE, 1);
        shopping1.buy(STRAWBERRY, 1);
        shopping1.buy(MANGO, 1);
        SuperMarket superMarket = new SuperMarket(shopping, shopping1);
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName() + "需要付款:" + superMarket.checkout() + "元");
    }

    public static void customerD() {
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName() + " 开始购买");
        Shopping shopping = new Shopping();
        shopping.buy(APPLE, 1);
        shopping.buy(STRAWBERRY, 8);
        shopping.buy(MANGO, 2);
        BasePromotion basePromotion = new CouponPromotion();
        SuperMarket superMarket = new SuperMarket(basePromotion, shopping);
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName() + "需要付款:" + superMarket.checkout() + "元");
    }

}
